package com.moussa.mike;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class YouTubeAdapter extends ArrayAdapter<YouTubeVideo> {

	private List<YouTubeVideo> mVideoList;
	private Activity context;
	
	public YouTubeAdapter(Context context, int textViewResourceId,
			List<YouTubeVideo> mVideoList) {
		super(context, textViewResourceId, mVideoList);
		this.mVideoList = mVideoList;
		this.context = (Activity) context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		YouTubeVideo myVideo = mVideoList.get(position);
		
		String title = myVideo.getTitle();
		String author = myVideo.getAuthor();
		String duration = myVideo.getDurationString();
		float rating = myVideo.getUserRating();
		float cRating = myVideo.getCaptionRating();
		
		LayoutInflater inflater=context.getLayoutInflater(); 
		View row = inflater.inflate(R.layout.row_layout,parent,false);
		
		TextView mTitle = (TextView)row.findViewById(R.id.title);
		TextView mTuthor = (TextView)row.findViewById(R.id.author);
		TextView mDuration = (TextView)row.findViewById(R.id.duration);
		RatingBar mRating = (RatingBar)row.findViewById(R.id.rating);
		TextView captionrating = (TextView)row.findViewById(R.id.captionrating);
		
		mTitle.setText(title);
		mTuthor.setText(author);
		mDuration.setText(duration); //TODO need to convert to hh:mm:ss
		mRating.setRating(rating);
		captionrating.setText(String.format("Author's Channel Caption Rating: %.0f%%",cRating));
		
		
		return row;
	}
	
	
	

}
